﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HanGu.Services.Interface;
using HanGu.Entity;

namespace HanGu.Services
{
    public class ChangeChargeRecordeService : BaseService,IChangeChargeRecorde
    {

        public List<VChangeChargeRecorde> GetAll(UniversallySearchParam searchParam)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {

                var query = obj.VChangeChargeRecorde.Where(c => 1 == 1);
                if (searchParam.IntObj1 != 0)
                {
                    query = query.Where(c => c.VIPID == searchParam.IntObj1);
                }
                if (searchParam.StarDateTime.HasValue)
                {
                    query = query.Where(c => c.ChangeTime >= searchParam.StarDateTime);
                }
                if (searchParam.EndDateTime.HasValue)
                {
                    query = query.Where(c => c.ChangeTime <= searchParam.EndDateTime);
                }
                return base.Paging<VChangeChargeRecorde, DateTime?>(c => c.ChangeTime, query, searchParam.Pagination).ToList();
            }
        }

        public List<ChangeChargeRecorde> GetByID(int id)
        {
            using (HaiGuEntities obj = new HaiGuEntities())
            {
                return obj.ChangeChargeRecorde.Where(c => c.VIPID == id).OrderByDescending(c=>c.ChangeTime).ToList();
            }
        }

       
        public bool Add(ChangeChargeRecorde model)
        {
            try
            {
                this.Add<ChangeChargeRecorde>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Update(ChangeChargeRecorde model)
        {
            try
            {
                this.Update<ChangeChargeRecorde>(model);
                return true;
            }
            catch { return false; }
        }

        public bool Delete(int id)
        {
            try
            {
                this.Delete<ChangeChargeRecorde>(c => c.ID == id);
                return true;
            }
            catch { return false; }
        }

        
    }
}
